package com.wfs.array;

/**
 * 石头阵游戏：数据初始化
 */
public class ArrayTest5 {
    public static void main(String[] args) {
        init(5);
    }

    // 初始化
    public static void init(int n) {
        int[][] arr = new int[n][n];
        int count = 1;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = count++;
            }
        }
        // 打印
        System.out.println("打印初始数组");
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }
        // 随机数字
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                int m = (int) (Math.random() * arr.length);
                int p = (int) (Math.random() * arr.length);
                int temp = arr[i][j];
                arr[i][j] = arr[m][p];
                arr[m][p] = temp;
            }
        }
        // 打印
        System.out.println("打印随机数组");
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }
    }
}
